<template>
  <BasicTable @register="registerTable" @resize-column="handleResizeColumn">
    <template #action="{ record }">
      <TableAction
        :actions="[
          {
            icon: 'material-symbols:calendar-month-outline-rounded',
            tooltip: '月统计',
            onClick: handleGo.bind(null, record, 'MonthlyStatistics'),
            ifShow: () => record.isFlowExist,
          },
          {
            icon: 'iwwa:year',
            tooltip: '年统计',
            onClick: handleGo.bind(null, record, 'YearStatistics'),
            ifShow: () => record.isFlowExist,
          },
        ]"
      />
    </template>
  </BasicTable>
</template>
<script lang="ts">
  import { defineComponent, onMounted, ref } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getFlowStatList, getAdminFlowEditNode } from '/@/api/flowManage/flowManage';
  import { useGo } from '/@/hooks/web/usePage';
  import { useTabs } from '/@/hooks/web/useTabs';

  import { columns, searchFormSchema } from './flowStatistics.data';

  export default defineComponent({
    name: 'Notice',
    components: { BasicTable, TableAction },
    setup() {
      const { setTitle } = useTabs();
      const go = useGo();
      onMounted(async () => {});

      const [registerTable, { reload }] = useTable({
        title: '流程统计',
        api: getFlowStatList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        searchInfo: {
          op: 'search',
        }, //额外的参数
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        indexColumnProps: { width: 50 },
        showIndexColumn: true,
        actionColumn: {
          width: 120,
          title: '统计',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });

      onMounted(() => {});
      const handleGo = async (record, type) => {
        console.log({ record, type });
        // const data = await getAdminFlowEditNode({ code: record.typeCode });
        go({
          path: '/flowManagement',
          query: {
            isNotQuery: 2,
            type,
            title: `${record.name}${type == 'MonthlyStatistics' ? '单月统计' : '年统计'}`,
            typeName: record.typeName,
            layer: record.layer,
            typeCode: record.typeCode,
          },
        });
      };
      return {
        registerTable,
        handleResizeColumn: (w, col) => {
          col.width = w;
        },
        handleGo,
      };
    },
  });
</script>
